<template>
    <div>
        <h1>登录</h1>
        <table>
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td><input type="text" v-model="info.name"/></td>
                </tr>
               
                <tr>
                    <td align="right">密码</td>
                    <td><input type="password" v-model="info.pwd"/></td>
                </tr> 
                <tr>
                    <td align="right"></td>
                    <td><button class="btn btn-success"  @click="login">登录</button></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';

//
const router=useRouter();
const info=ref({
    name:'',
    phone:'',
    pwd:''
})

const login=()=>{
    if(info.value.name==''){
        alert('用户名不能为空!');
        return;
    }
    if(info.value.pwd==''){
        alert('密码不能为空!');
        return;
    }

    axios.get("https://localhost:7161/api/User/Deng?name="+info.value.name+"&pwd="+info.value.pwd)
    .then(res=>{
        if(res.data==1){
            alert('登录成功!');
        }
        else{
            alert('登录错误!');
        }
    })
    .catch(err=>{
        console.log(err);
    })

}

</script>

